package com.zy.controller;

import com.zy.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @date 2020/5/8 - 9:42
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionCatch {
    /**
     * 全局异常捕捉处理
     * @param ex
     * @return
     */
    @ExceptionHandler({RuntimeException.class})
    public ResultVo errorHandler(RuntimeException ex) {
        if(ex instanceof UnauthorizedException){
            log.error("小垃圾   你没有权限",ex);
        }else {
            log.error(ex.getMessage(),ex);
        }
        return ResultVo.fail("查询操作失败!");
    }
}
